cmake_minimum_required(VERSION 3.00)

project(O5G)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

set(SYSTEM_CPU_COMPILER "${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}_${CMAKE_C_COMPILER_ID}")
string(TOLOWER "${SYSTEM_CPU_COMPILER}" SYSTEM_CPU_COMPILER)
message("SYSTEM_CPU_COMPILER: ${SYSTEM_CPU_COMPILER}")

add_definitions(-DASN_DISABLE_OER_SUPPORT=1)

if (O5G_TEST)
    add_definitions(-DO5G_TEST=1)
endif ()

if (O5G_TEST)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/app/bin)
else ()
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/app/bin)
endif ()

add_definitions(-DO5G_SOURCE_DIR="${PROJECT_SOURCE_DIR}")

include_directories(src/ccore/asn1c/skeletons)
include_directories(src/ccore/asn1c/rrc)
include_directories(src/ccore/asn1c/ngap)
include_directories(src/ccore/gtpu/nw-gtpv1u/include)
include_directories(src/ccore/gtpu/nw-gtpv1u/shared)

file(GLOB ASN1C_LIB lib/3rdParty/asn1c/libasn1c_${SYSTEM_CPU_COMPILER}.a)
file(GLOB NNG_LIB lib/3rdParty/nng/libnng_${SYSTEM_CPU_COMPILER}.a)
file(GLOB RRC_LIB lib/3rdParty/asn1c/librrc_asn1_${SYSTEM_CPU_COMPILER}.a)
file(GLOB NGAP_LIB lib/3rdParty/asn1c/libngap_asn1_${SYSTEM_CPU_COMPILER}.a)

file(GLOB_RECURSE COMM_LIB_SRCS "lib/*.c")
file(GLOB_RECURSE APP_CORE_SRCS
        "src/ccore/common/*.c"
        "src/ccore/asn1c/codec/*.c"
        "src/ccore/e1/*.c"
        "src/ccore/f1/*.c"
        "src/ccore/f2/*.c"
        "src/ccore/gtpu/*.c"
        "src/ccore/ng/*.c"
        "src/ccore/phy/*.c"
        "src/ccore/sctp/*.c"
        "src/ccore/src/*.c"
        "src/ccore/tables/*.c"
        "src/ccore/xn/*.c"
        "src/ccore/misc/*.c")

add_subdirectory(src/o5gcn)
add_subdirectory(src/o5gran)
add_subdirectory(src/o5gue)

if (O5G_TEST)
    file(GLOB_RECURSE TESTS_SRCS "tests/*.c" "tests/*.cpp")
    set(TEST_APP_SRCS ${CN_SRCS} ${RAN_SRCS} ${UE_SRCS} ${COMM_LIB_SRCS} ${APP_CORE_SRCS} ${TESTS_SRCS})
#    单元测试要排除CN/RAN/UE的app.c
    list(FILTER TEST_APP_SRCS EXCLUDE REGEX ".*/app.c$")
#    message(${TEST_APP_SRCS})
    add_executable(TEST_APP ${TEST_APP_SRCS})
    target_link_libraries(TEST_APP pthread sctp rt m ${RRC_LIB} ${NGAP_LIB} ${ASN1C_LIB} ${NNG_LIB})

    add_custom_target(run
            COMMAND TEST_APP
            DEPENDS TEST_APP
            WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/app/bin
            )
endif ()